package com.zhuzhiwen.service.user;

import com.zhuzhiwen.dao.BaseDao;
import com.zhuzhiwen.dao.user.UserDao;
import com.zhuzhiwen.dao.user.UserDaoImpl;
import com.zhuzhiwen.pojo.User;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @program: MySQL_JSP_Term
 * @description: 用户继承
 * @author: 朱志文
 * @create: 2021-12-08 12:30
 **/
public class UserServiceImpl implements UserService{
    //业务层都会调用dao层，所以我们要引入Dao层;
    private UserDao userDao;
    public UserServiceImpl(){
        userDao=new UserDaoImpl();
    }

    @Override
    public User login(String userCode, String password) {
        Connection connection=null;
        User user=null;

        try {
            connection = BaseDao.getConnection();
            //通过业务层调用对应的具体的数据库操作
            user=userDao.getLoginUser(connection,userCode);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            BaseDao.closeResource(connection,null,null);
        }
        return  user;
    }
   @Test
    public void test(){
       UserServiceImpl userService = new UserServiceImpl();
       User admin = userService.login("root", "123456");
       System.out.println(admin.getUserPassword());
   }
}
